package cm.day13.Test3;

import java.io.*;
import java.net.Socket;

public class Client {
    public static void main(String[] args) throws IOException {
        //1.创建Socket对象，并连接服务器
        Socket socket = new Socket("127.0.0.1", 10086);
        //读取本地文件
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("d:/aaa/bbb.txt"));
        OutputStream ops = socket.getOutputStream();
        BufferedOutputStream bos = new BufferedOutputStream(ops);
        int len = -1;
        byte[] bytes = new byte[1024];
        while ((len = bis.read(bytes)) != -1) {
            bos.write(bytes, 0, len);
        }
        //结束标记
        socket.shutdownOutput();
        //接收服务器回写数据
        BufferedReader br=new BufferedReader(new InputStreamReader(socket.getInputStream()) );
        System.out.println(br.readLine());

        //释放资源
        socket.close();
    }
}
